# encoding: utf-8
# @File  : user.py
# @Author: shaoyun
# @Date  : 2025/05/11

from datetime import datetime
from typing import Optional, List, Dict, Any

from pydantic import BaseModel, Field, ConfigDict


class UserBase(BaseModel):
    """用户基本信息"""
    username: str
    email: str
    is_active: bool = True


class UserCreate(UserBase):
    """创建用户的请求模型"""
    password: str
    role: Optional[str] = "user"  # 默认角色为普通用户


class UserUpdate(BaseModel):
    """更新用户的请求模型"""
    username: Optional[str] = None
    email: Optional[str] = None
    password: Optional[str] = None
    role: Optional[str] = None
    is_active: Optional[bool] = None


class UserInDB(UserBase):
    """数据库中的用户模型"""
    id: str
    role: str
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)  # 替代 orm_mode


class UserWithTasks(UserInDB):
    """包含任务的用户模型"""
    tasks: Optional[List[Dict[str, Any]]] = None